public class Main {
    volatile static int count = 1;
    public static void main(String[] args) {

        Thread t1 = new Thread( () -> {
            while (true) {
                if (count % 3 == 1) {
                    System.out.println("A");
                    count++;
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        });
        Thread t2 = new Thread( () -> {
            while (true) {
                if (count % 3 == 2) {
                    System.out.println("B");
                    count++;
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        Thread t3 = new Thread( () -> {
            while (true) {
                if (count % 3 == 0) {
                    System.out.println("C");
                    count++;
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        });


        t1.start();
        t2.start();
        t3.start();
    }
}
